#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <ctype.h>
#include <time.h>
#include <limits.h>
#include <stdalign.h>
#include "h/names.h"

#define LEN 81
#define SWAP(type, a, b)    do {type c=a; a=b; b=c;} while(0)

char * s_gets(char *, int);
void eatline(void);

inline double square(double);
double square(double x)
{
    return x * x;
}

#define MYTYPE(X) _Generic((X), \
    int: "int",\
    double: "double",\
    float: "float",\
    long: "long",\
    char: "char",\
    int *: "pointer int",\
    double *: "pointer double",\
    unsigned: "unsigned",\
    default: "other"\
)

int main(void)
{
    int a = 1;
    printf("%s\n",  MYTYPE(a));
    double b = 2.0 * a;
    printf("%s\n",  MYTYPE(b));
    printf("%s\n",  MYTYPE(0l));
    printf("%s\n",  MYTYPE(1.0));
    printf("%s\n",  MYTYPE(1.0f));
    printf("%s\n",  MYTYPE((char)'a'));
    printf("%s\n",  MYTYPE(& a));
    printf("%s\n",  MYTYPE(& b));
    printf("%s\n",  MYTYPE((unsigned)-1));

    return 0;
}

char * s_gets(char * str, int n)
{
    char * ret_val;
    char * find;

    if ((ret_val = fgets(str, n, stdin))) {
        find = strchr(str, '\n');
        if (find)
            *find = 0;
        else
            while (getchar() != '\n')
                ;
    }

    return ret_val;
}

void eatline(void)
{
    while (getchar() != '\n')
        ;
}
